/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */

package space.math;

/**
 *
 * @author Pierre
 */
public class Vector2f {

    private float x, y;

    public Vector2f(float x, float y) {
        this.x = x;
        this.y = y;
    }

    public Vector2f() {
    }

    public float x() {
        return x;
    }

    public float y() {
        return y;
    }

    public Vector2f assignSub(final Vector2f v) {
        x -= v.x;
        y -= v.y;
        return this;
    }

    public void assign(float x, float y) {
        this.x = x;
        this.y = y;
    }
    public Vector2f assign(Vector2f v) {
        this.x = v.x;
        this.y = v.y;
        return this;
    }

    public static float det(final Vector2f u, final Vector2f v) {
        assert !u.corrupted();
        assert !v.corrupted();
        final float d = u.x * v.y - u.y * v.x;
        assert !Float.isNaN(d);
        assert !Float.isInfinite(d);
        return d;
    }
    
    private boolean corrupted(){
        return Float.isNaN(x)||Float.isInfinite(x)||Float.isNaN(y)||Float.isInfinite(y);
    }
}
